#include "twobuttonswindow.h"
#include "ui_twobuttonswindow.h"
#include <QDebug>

TwoButtonsWindow::TwoButtonsWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::TwoButtonsWindow)
{
    ui->setupUi(this);
    connect (ui->pushButtonTrain, SIGNAL(clicked()), this, SLOT(createNetwork()));
    connect (ui->pushButtonOther, SIGNAL(clicked()), this, SLOT(openPatientScreen()));
}

TwoButtonsWindow::~TwoButtonsWindow()
{
    delete ui;
}

void TwoButtonsWindow::createNetwork() {
    QMessageBox msgBox;
    ui->label->setText("Started network training - it may take a little time...");
    ui->label->update();
    qDebug() << "Started train";
    struct fann *ann = fann_create_sparse (1.0, 3, 24, 10, 3);
    //TODO: add auto fndata generation script running
    fann_train_on_file(ann, "..\\Patients\\train.fndata", 2000, 100, 0.0001);
    fann_save(ann, "..\\net\\cell_classify.net");
    msgBox.close();
    qDebug() << "Finished";
    ui->label->setText("");
    ui->label->update();
    msgBox.setText("Network have been trained.");
    msgBox.setModal(true);
    msgBox.exec();
    fann_destroy(ann);
}

void TwoButtonsWindow::openPatientScreen(){
    lw = new CLoadWindow();
    lw->show();
}
